//
//  AppDelegate.swift
//  sinaWeibo
//
//  Created by 董艳武 on 16/1/30.
//  Copyright © 2016年 董艳武. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
//        sleep(2)
       
        setUpTintColor()
        
        window = UIWindow(frame:UIScreen.mainScreen().bounds)
        
        window?.rootViewController = self.changeRootViewController()
//        let vc = DYWComposeController()
//        let nav = DYWBaseNavController(rootViewController:vc)
//        window?.rootViewController = nav
//        window?.rootViewController = DYWPickerSelector()
        
        window?.backgroundColor = UIColor.whiteColor()
        
        window?.makeKeyAndVisible()
        
        refisterNoti()
        
        return true
    }

    private func setUpTintColor () {
        // 设置导航栏的全局样式
        UINavigationBar.appearance().tintColor = themeColor
        // 设置标签栏的全局样式
        UITabBar.appearance().tintColor = themeColor
    }
    
    // MARK:--注册通知中心
    private func refisterNoti () {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "selectController:", name: choseController, object: nil)
    }
   
    /// 切换控制器的方法
    private func changeRootViewController () -> UIViewController {
        if DYWOauthViewModel.sharedInstance.isVistor == true {
            return DYWMainController()
        }
        
        return DYWLoadingController()
        
    }
    
    // MARK:--接收到通知做的事情 
    @objc private func selectController(n:NSNotification) {
       // 若发送的
       self.window?.rootViewController =  n.object == nil ? DYWLoadingController() : DYWMainController()
        
    }
    
    // MARK:--移除通知
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

}

